//
//  FirstAuditingDetailView.m
//  优学荟管理系统
//
//  Created by 星道 on 17/7/13.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "FirstAuditingDetailView.h"

@implementation FirstAuditingDetailView
{
    IBOutlet UILabel *_ID;
    IBOutlet UILabel *_OName;
    IBOutlet UILabel *_Account;
    IBOutlet UILabel *_Name;
    IBOutlet UILabel *_ShiFu_Price;
    IBOutlet UILabel *_DiKou_Price;
    IBOutlet UILabel *_CountPrice;
    IBOutlet UIImageView *_CloseImg;

    IBOutlet UIView *_BackView;
    void (^_ClickCommit)(NSString *);
}

+ (instancetype)ConsumeSure_Model:(FirstAuditingDetailListModel *)Model ClickCommit:(void (^)(NSString *))ClickCommit
{
    return [[self alloc] initWithModel:Model ClickCommit:ClickCommit];
}




//初始化
- (instancetype)initWithModel:(FirstAuditingDetailListModel *)Model ClickCommit:(void (^)(NSString *))ClickCommit
{
    self = [[[NSBundle mainBundle] loadNibNamed:[FirstAuditingDetailView description] owner:nil options:nil] lastObject];
    if (self) {

        [[UIApplication sharedApplication].keyWindow addSubview:self];

        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT);

        _ClickCommit = ClickCommit;

        //textfield加上阴影效果
        [[_BackView layer] setMasksToBounds:YES];
        [[_BackView layer] setShadowOffset:CGSizeMake(1, 1)]; // 阴影的范围
        [[_BackView layer] setShadowRadius:3];                // 阴影扩散的范围控制
        [[_BackView layer] setShadowOpacity:1];               // 阴影透明度
        [[_BackView layer] setShadowColor:[UIColor blackColor].CGColor]; // 阴影的颜色
        [_BackView setClipsToBounds:NO];

        //添加关闭手势
        [_CloseImg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Close)]];

        self.alpha = 0;

        // 界面传值
        [self SetupView_Model:Model];

        //弹出窗口
        [self Show];
    }
    return self;
}




/**
 界面传值
 */
- (void)SetupView_Model:(FirstAuditingDetailListModel *)Model
{
    _ID.text          = [Model.ID stringValue];
    _OName.text       = Model.sellerName;
    _Account.text     = Model.username;
    _Name.text        = Model.petName;
    _ShiFu_Price.text = [Model.actualPaid stringValue];
    _DiKou_Price.text = [Model.coins stringValue];
    _CountPrice.text  = [@([Model.actualPaid floatValue] + [Model.coins floatValue]) stringValue];

}




/**
 显示自己
 */
- (void)Show {
    //动画展示
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
    }];
}



/**
 移除自己，并关闭界面
 */
- (IBAction)Close {

    [self endEditing:YES];

    //动画开始
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}
@end
